Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly clean up externalizeUTWithJson #1531

Closed
wants to merge 3 commits into from

Conversation

Miepee
Copy link
Contributor

@Miepee Miepee commented Nov 15, 2023

Description

See title

Caveats

I did not test this at all

Copy link

github-actions bot commented Nov 15, 2023

Comment on lines -69 to -90
if (Data.GeneralInfo.Major < 2) // Undertale PC (GMS1)
{
ImportGMLString("gml_Script_textdata_en", @"
if (variable_global_exists(""text_data_en""))
ds_map_destroy(global.text_data_en);
global.text_data_en = scr_84_load_map_json(program_directory + ""\lang\"" + ""lang_en.json"");");
ImportGMLString("gml_Script_textdata_ja", @"
if (variable_global_exists(""text_data_ja""))
ds_map_destroy(global.text_data_ja);
global.text_data_ja = scr_84_load_map_json(program_directory + ""\lang\"" + ""lang_ja.json"");");
}
else
{
ImportGMLString("gml_Script_textdata_en", @"
if (variable_global_exists(""text_data_en""))
ds_map_destroy(global.text_data_en);
global.text_data_en = scr_84_load_map_json(program_directory + ""\lang\\"" + ""lang_en.json"");");
ImportGMLString("gml_Script_textdata_ja", @"
if (variable_global_exists(""text_data_ja""))
ds_map_destroy(global.text_data_ja);
global.text_data_ja = scr_84_load_map_json(program_directory + ""\lang\\"" + ""lang_ja.json"");");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you checked if ""\lang\\"" can be ""\lang\"" for GMS 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldnt matter.
it essentially wants to do program directory + \lang\ + lang_ja.json (or lang_en). Hence why I replaced it with a slash, as that then also works for all operating systems properly instead of just Windows. and these two paths program_directory/lang or program_directory/////lang are the same.

Comment on lines -157 to -216
if (Data.GeneralInfo.Major < 2) // Undertale PC (GMS1)
// Undertale PC (GMS1)
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json"));

string pattern = ".*ds_map_create\\(\\)";
string replacement = "{";
input = Regex.Replace(input, pattern, replacement);

// Undertale Switch/Probs other consoles (GMS2)
if (Data.GeneralInfo.Major >= 2)
{
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json"));

string pattern = ".*ds_map_create\\(\\)";
string replacement = "{";
input = Regex.Replace(input, pattern, replacement);

pattern = @"\\";
replacement = @"\\";
input = Regex.Replace(input, pattern, replacement);

pattern = @""" \+ '""' \+ """;
replacement = @"\""";
input = Regex.Replace(input, pattern, replacement);


pattern = @"'""' \+ """;
replacement = @"""\""";
input = Regex.Replace(input, pattern, replacement);


pattern = @""" \+ '""'";
replacement = @"\""""";
input = Regex.Replace(input, pattern, replacement);


pattern = @"'""'";
replacement = @"\""";
input = Regex.Replace(input, pattern, replacement);


input = input.Replace(@"\"",", @"\"""",");

pattern = @"ds_map_add\(global\.text_data_.., ("".*""), ("".*"")\)";
replacement = @" $1: $2,";
input = Regex.Replace(input, pattern, replacement);

pattern = @",\n\Z";
replacement = "\n}";
input = Regex.Replace(input, pattern, replacement);

File.WriteAllText(Path.Combine(langFolder, "lang_" + language + ".json"), input);

IncProgressLocal();
UpdateProgressValue(GetProgress());
}
else // Undertale Switch/Probs other consoles (GMS2)
{
string input = File.ReadAllText(Path.Combine(langFolder, "lang_" + language + ".json"));

string pattern = ".*ds_map_create\\(\\)";
string replacement = "{";
input = Regex.Replace(input, pattern, replacement);

pattern = @"ds_map_add\(global\.text_data_.., ("".*""), ("".*"")\)";
replacement = @" $1: $2,";
input = Regex.Replace(input, pattern, replacement);

pattern = @",\n\Z";
replacement = "\n}";
input = Regex.Replace(input, pattern, replacement);

File.WriteAllText(Path.Combine(langFolder, "lang_" + language + ".json"), input);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same question here as for lines 69-90

@colinator27
Copy link
Member

This should probably be redone when the Underanalyzer decompiler is merged in. In its current state, this script produces invalid JSON, due to the regex hacks of parsing the decompiler's output string (so we should hold off on merging).

With Underanalyzer, the AST can be directly returned from the decompiler, skipping the step of printing to a string, and allowing a simple iteration over the raw string contents in the tree.

@Miepee Miepee marked this pull request as draft July 1, 2024 13:25
@Miepee Miepee closed this Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants